package com.tutu.utils.weixin;

import com.tutu.utils.WxMsgPushUtil;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType;

@Configuration
public class MenuConfig {

    @Value("${wechat.appId}")
    private String appId;

    @Bean
    public WxMenu wxMenu() {
        WxMenu menu = new WxMenu();

        WxMenuButton button1 = new WxMenuButton();
        button1.setType(MenuButtonType.VIEW);
        button1.setName("个人中心");
        button1.setUrl(WxMsgPushUtil.getWeChatMenuUrl(WxMsgPushUtil.personCenterUrl));

        WxMenuButton button2 = new WxMenuButton();
        button2.setName("数据中心");
        button2.setType(MenuButtonType.CLICK);
        button2.setKey("DATA_CENTER");

        WxMenuButton subButton1 = new WxMenuButton();
        subButton1.setType(MenuButtonType.VIEW);
        subButton1.setName("数据监控");
        subButton1.setUrl(WxMsgPushUtil.getWeChatMenuUrl(WxMsgPushUtil.timeDataUrl));

        WxMenuButton subButton2 = new WxMenuButton();
        subButton2.setType(MenuButtonType.VIEW);
        subButton2.setName("历史预警");
        subButton2.setUrl(WxMsgPushUtil.getWeChatMenuUrl(WxMsgPushUtil.historyMsgUrl));

        button2.getSubButtons().add(subButton1);
        button2.getSubButtons().add(subButton2);

        menu.getButtons().add(button1);
        menu.getButtons().add(button2);

        return menu;
    }
}